#pragma once
#include <cstdint>
#include <thread>
#include <atomic>
#include <sys/socket.h>
#include <netinet/in.h>
#include "LockFreeRingBuffer.h"
#include "MemoryPool.h"
#include "OrderPacket.h"

class Sender
{
public:
    Sender(const char *target_ip, uint16_t target_port, LockFreeRingBuffer<OrderPacket> &ringBuffer, MemoryPool& memoryPool, int cpu_id);
    ~Sender();

    void start();
    void stop();

private:
    void run();

    static constexpr int MAX_BATCH = 32; // 每批最多发32条

    int sock_;
    sockaddr_in target_addr_;
    LockFreeRingBuffer<OrderPacket> &ringBuffer_;
    std::atomic<bool> running_;
    std::thread thread_;
    MemoryPool& memoryPool_;
    int cpu_id_;
};
